import PropTypes from "prop-types";
import React from "react";
export const DemoOne = ({ title = "DemoOne", name = "DemoOne", children }) => {
  const childrenArr = React.Children.toArray(children);
  console.log(childrenArr);
  let headerSlot = [],
    footerSlot = [],
    middleSlot = [];
  childrenArr.forEach((child) => {
    let slot = child.props;
    if (slot === "header") {
      headerSlot.push(child);
    } else if (slot === "footer") {
      footerSlot.push(child);
    } else {
      middleSlot.push(child);
    }
  });
  return (
    <div>
      函数式组件-{title}-{name}
			{footerSlot}
      {headerSlot}
      {middleSlot}
    </div>
  );
};

//设置类型检查
DemoOne.prototype = {
  title: PropTypes.string.isRequired,
  name: PropTypes.string.isRequired,
  num: PropTypes.number,
};

//设置默认值
// DemoOne.defaultProps = {
// 		title: "默认标题",
// 		name: "默认名称",
// };

//Object.freeze(); 冻结一个对象，使其不可修改，不可劫持
//Object.isFrozen(); 检查一个对象是否被冻结
//Object.seal();密封一个对象；不能新增、删除属性，不可劫持，但可以修改属性的值
//Object.isSealed();检查一个对象是否被密封
//Object.preventExtensions(); 不可扩展一个对象，不能新增属性，其余操作都可以
//Object.isExtensible(); 检查一个对象是否可扩展
